<template>
  <view class="love">
    <view class="love-love" @click.stop="onMark('remind')">{{ remindid ? '已' : '' }}订阅</view>
    <view class="love-fav" @click.stop="onMark('love')">{{ loveid ? '已' : '' }}收藏</view>
  </view>
</template>

<script>
import { mapActions } from 'vuex'
import { isLogin } from '@/utils'
export default {
  props: ['vid', 'sid', 'cid'],
  data() {
    return {
      loveid: '',
      remindid: ''
    }
  },
  methods: {
    ...mapActions('love', ['getScore', 'mark']),
    onMark(type) {
      const that = this
      if (isLogin()) {
        this.mark({
          type,
          id: this.vid,
          cid: this.cid
        }).then(res => {
          debugger
          if (res.code === 1) {
            that.get()
          }
          uni.showToast({
            title: res.msg
          })
        })
      } else {
        uni.reLaunch({
          url: '/pages/login/index'
        })
      }
    },
    get() {
      const { vid, sid } = this
      this.getScore({ id: vid, sid }).then(res => {
        const { remindid, loveid } = res.data
        this.remindid = remindid
        this.loveid = loveid
      })
    }
  },
  mounted() {
    if (isLogin()) {
      this.get()
    }
  }
}
</script>

<style lang="scss" scoped>
.love {
  width: 210rpx;
  font-size: 24rpx;
  display: flex;
  justify-content: space-between;
  text-align: center;
  &-love,
  &-fav {
    width: 100rpx;
    height: 40rpx;
    line-height: 40rpx;
    border: 1rpx solid #ddd;
    border-radius: 5rpx;
  }
}
</style>
